<?php
/**
 * Created by PhpStorm.
 * User: Emmett
 * Date: 2016/8/30
 * Time: 17:30
 */

namespace Business\Home;

use Common\Common\GlobalParam;

class EmployeeHomeStrategy extends HomeStrategyBase
{
    public function index()
    {
        parent::index();
        $user_id = $this->mvc_controller->current_user['id'];
        $crm_custom = M('crm_custom');

        $this->follow_count($user_id, $crm_custom);
        $this->signed_count($user_id, $crm_custom);
        $this->add_count($user_id, $crm_custom);

        $crm_activity = M('crm_activity');

        $this->phone_count($user_id, $crm_activity);
    }

    protected function follow_count($user_id, $crm_custom)
    {
        //我跟进的客户数量
        $condition = array();
        $condition['leader_user_id'] = $user_id;
        $condition['state'] = GlobalParam::$Custom_State_Distributed;

        $follow_count = $crm_custom->where($condition)->count();
        $this->mvc_controller->assign('follow_count', $follow_count);
    }

    protected function signed_count($user_id, $crm_custom)
    {
        //我签约的客户数量
        $condition = array();
        $condition['sign_user_id'] = $user_id;
        $condition['state'] = GlobalParam::$Custom_State_Signed;

        $signed_count = $crm_custom->where($condition)->count();
        $this->mvc_controller->assign('signed_count', $signed_count);
    }

    protected function add_count($user_id, $crm_custom)
    {
        //我新增的客户数量
        $condition = array();
        $condition['add_user_id'] = $user_id;
        $condition['state'] = array('egt', GlobalParam::$Custom_State_Undistributed);

        $add_count = $crm_custom->where($condition)->count();
        $this->mvc_controller->assign('add_count', $add_count);
    }

    protected function phone_count($user_id, $crm_activity)
    {
        //我的电话量
        $condition = array();
        $condition['add_user_id'] = $user_id;
        $condition['type'] = array('eq', 1);
        $condition['state'] = array('eq', 0);

        $phone_count = $crm_activity->where($condition)->count();
        $this->mvc_controller->assign('phone_count', $phone_count);
    }
}